// pages/new_output/new_output.js
Page({
  data:{
    i:0,
    name:'',
    hasined:false,
    gp:["gp0","gp1","gp2","gp3","gp4","gp5","gp6","gp7","gp8","gp9"],
    good:{
      type: String,
      title:'',
      detail:'',
      price:'',
    }
  },
  onReady(){
    var self = this;
    wx.getStorage({
      key: 'individual',
      success: function(res){
        self.setData({
          name:res.data.name,
          hasined:true
        })
      }
    });
  },
  formSubmit(e){
    if(!this.data.hasined){
      wx.showModal({
        title:'提示',
        content:'请填写实名信息',
        showCancel:false
      })
    }
    else{
    const value = e.detail.value;
    if (value.title && value.detail && value.price){
      wx.setStorage({
        key: this.data.gp[this.data.i],
        data: value,
        success(){
          wx.navigateBack();
        }
      });
      self.setData({
        i:i+1
      });
      const db = wx.cloud.database();
  db.collection('goods').add({
    // data 字段表示需新增的 JSON 数据
    data: {
      name:this.data.name,
      title:value.title,
      detail:value.detail,
      price:value.price
    },
    success: function(res) {
      // res 是一个对象，其中有 _id 字段标记刚创建的记录的 id
      console.log(res)
    }
    })
    }else{
      wx.showModal({
        title:'提示',
        content:'请填写完整资料',
        showCancel:false
      })
    }
  }
}
})